import http from "../../util/http";
const module = {
  namespaced: true,
  state: {
    firstNum: 0,
    finished: false,
    loading:false,
    filmList: [],
  },
  mutations: {
    setFilmList(state, list) {
      state.filmList = list;
    },
    setFirstNum(state, firstNum) {
      state.firstNum = firstNum;
    },
    setFinished(state, finished) {
      state.finished = finished;
    },
    setLoading(state, loading) {
      state.loading = loading;
    }
  },
  //处理异步操作
  actions: {
    //获取电影信息
    getFilmList(store,obj) {
      http({
        url: `/gateway?cityId=${obj.cityId}&pageNum=${obj.pageNum}&pageSize=10&type=1&k=628655`,
        headers: {
          "X-Host": "mall.film-ticket.film.list",
        },
      }).then((res) => {
        store.commit("setFilmList", [...store.state.filmList, ...res.data.data.films]);
        // store.state.loading=false;
        store.commit("setLoading", false);
        if (res.data.data.films.length === 0 || store.state.filmList.length === res.data.data.total) {
           store.commit("setFinished", true);
          // store.state.finished=true;
          console.log("达到总长度");
        }
      });
    },
  }
}
export default module;